// 写法 vue3 Composition API 完全类似
import { create } from "zustand";

type CounterState = {
  count: number;
  name: string;
  add: () => void;
  sub: () => void;
  double: () => void;
  changeName: () => void;
};

export const useCounter = create<CounterState>((set) => ({
  count: 0,
  name: "",
  add: () => set((state) => ({ count: state.count + 1 })),
  sub: () => set((state) => ({ count: state.count - 1 })),
  double: () => set((state) => ({ count: state.count * 2 })),
  changeName: () => set(() => ({ name: "heyi" + Math.random() })),
}));
